package org.example.demo.service.impl;

import org.example.demo.broker.ProducerClient;
import org.example.demo.config.properties.QueueConfigProperties;
import org.example.demo.domain.Message;
import org.example.demo.domain.MessageRetryType;
import org.example.demo.domain.MessageType;
import org.example.demo.service.IProducerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class ProducerServiceImpl implements IProducerService {
    private static final Logger LOGGER = LoggerFactory.getLogger(ProducerServiceImpl.class);

    @Autowired
    private ProducerClient client;
    @Autowired
    private QueueConfigProperties properties;

    @Override
    public void sendDemoMessage(Long demoId) {
        Message message = Message.build()
                .withExchange(this.properties.getExchange())
                .withRoutingKey(this.properties.getRoutingKey().get("test"))
                .withMessageId(UUID.randomUUID().toString())
                .withMessageRetryType(MessageRetryType.NO)
                .withMessageType(MessageType.RAPID)
                .withAttribute("demoId", demoId)
                .withDelayMills(0);
        this.client.send(message);
    }
}
